package com.javalab._6feature._5annotation;

import java.lang.reflect.Method;

public class Test {
    public static void main(String[] args) throws ClassNotFoundException {
        Class<?> clazz = Class.forName("com.javalab.annotation.MyClass");
        // 判断类是否被注解修饰
        if (clazz.isAnnotationPresent(MyAnnotation.class)) {
            // 获取类注解
            MyAnnotation annotation = clazz.getAnnotation(MyAnnotation.class);
            System.out.println(annotation.identifier());

            Method[] methods = clazz.getDeclaredMethods();
            for (Method method : methods) {
                // 判断方法是否被注解修饰
                if (method.isAnnotationPresent(MyAnnotation2.class)) {
                    // 获取方法注解
                    MyAnnotation2 annotation2 = method.getAnnotation(MyAnnotation2.class);
                    System.out.println(annotation2.identifier());
                }
            }
        }
    }
}
